package cn.yunyichina.provider.iface.entity.common;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * Created by Lullaby on 2017/12/14
 */
@Getter
@Setter
public class HttpResponse<T> implements Serializable {

    private String code = HttpMessage.SUCCESS.getCode();

    private String message = HttpMessage.SUCCESS.getMessage();

    private T data;

    private static final Object constructorLock = new Object();

    public HttpResponse() {

    }

    public HttpResponse(HttpMessage httpMessage) {
        synchronized (constructorLock) {
            code = httpMessage.getCode();
            message = httpMessage.getMessage();
        }
    }

    public HttpResponse setHttpMessage(HttpMessage httpMessage) {
        synchronized (constructorLock) {
            code = httpMessage.getCode();
            message = httpMessage.getMessage();
            return this;
        }
    }

    public boolean isSuccess() {
        return this.getCode().equals(HttpMessage.SUCCESS.getCode());
    }

}
